def arrangement(m,n):
    a_ans=1
    try:
        for m in range(n,n-m,-1):
            a_ans=m*a_ans
    except:
        print("结果太大了，无法计算")
    else:
        return(a_ans)
                
def combination():
    try:
        b=arrangement(m,n)
        c=arrangement(m,m)
        c_ans=int(b/c)
    except:
        print("结果太大了，无法计算")
    else:
        return(c_ans)

while 1:
    try:
        a=int(input("请选择计算类型:(1.排列数 2.组合数)\n(输入其他字符退出程序)"))
    except:
        print("\n输入错误！")
        break
    else:
        if a==1:
            print("形如：A^m_n")
            try:
                m=int(input("m:"))
            except:
                print("输入错误！\n")
            else:
                if m<=0:
                    print("m必须大于0！\n")
                else:
                    try:
                        n=int(input("n:"))
                    except:
                        print("输入错误！\n")
                    else:
                        if n<=0:
                            print("n必须大于0！\n")
                        elif m>n:
                            print("n必须大于等于m！\n")
                        else:
                            ans=arrangement(m,n)
                            print("结果是：",ans)
                            print("")
            
        elif a==2:
            c_ans=1
            print("形如：C^m_n")
            try:
                m=int(input("m:"))
            except:
                print("输入错误！\n")
            else:
                if m<=0:
                    print("m必须大于0！\n")
                else:
                    try:
                        n=int(input("n:"))
                    except:
                        print("输入错误！\n")
                    else:
                        if n<=0:
                            print("n必须大于0！\n")
                        elif m>n:
                            print("n必须大于等于m！\n")
                        else:
                            ans=combination()
                            print("结果是：",ans)
                            print("")
            
        else:
            print("\n输入错误！\n")
            continue
print("感谢您的使用！")